package com.wjm.demo.test1.net_test.udp_socket_test.test;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPRece {
    public static void main(String[] args) throws Exception {
        DatagramSocket ds = new DatagramSocket(10000);//接收1111端口
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        ds.receive(dp);
        String ip = dp.getAddress().getHostAddress();
        int port = dp.getPort();
        String text = new String(dp.getData(), 0, dp.getLength());
        System.out.println(ip + ":" + port + ":" + text);
        ds.close();
    }
}
